﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_ProjectConfig : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainLowCodeProjectSchema");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainStdDomainDict",
                table: "MainStdDomainDict");

            migrationBuilder.RenameTable(
                name: "MainStdDomainDict",
                newName: "StdDomainDict");

            migrationBuilder.AddPrimaryKey(
                name: "PK_StdDomainDict",
                table: "StdDomainDict",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "MainProjectSchemaConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectSchemaName = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProjectSchemaConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainStdModelConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ModelCodg = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainProjectConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectName = table.Column<string>(type: "text", nullable: false),
                    ProjectConfigType = table.Column<int>(type: "integer", nullable: false),
                    ProjectSchemaConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProjectConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainProjectConfig_MainProjectSchemaConfig_ProjectSchemaConf~",
                        column: x => x.ProjectSchemaConfigId,
                        principalTable: "MainProjectSchemaConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "StdPhrDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PhrCode = table.Column<string>(type: "text", nullable: false),
                    PhrName = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    StdDomainDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    StdModelConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StdPhrDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StdPhrDict_MainStdModelConfig_StdModelConfigId",
                        column: x => x.StdModelConfigId,
                        principalTable: "MainStdModelConfig",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_StdPhrDict_StdDomainDict_StdDomainDictId",
                        column: x => x.StdDomainDictId,
                        principalTable: "StdDomainDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainProjectConfig_ProjectSchemaConfigId",
                table: "MainProjectConfig",
                column: "ProjectSchemaConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_StdPhrDict_StdDomainDictId",
                table: "StdPhrDict",
                column: "StdDomainDictId");

            migrationBuilder.CreateIndex(
                name: "IX_StdPhrDict_StdModelConfigId",
                table: "StdPhrDict",
                column: "StdModelConfigId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainProjectConfig");

            migrationBuilder.DropTable(
                name: "StdPhrDict");

            migrationBuilder.DropTable(
                name: "MainProjectSchemaConfig");

            migrationBuilder.DropTable(
                name: "MainStdModelConfig");

            migrationBuilder.DropPrimaryKey(
                name: "PK_StdDomainDict",
                table: "StdDomainDict");

            migrationBuilder.RenameTable(
                name: "StdDomainDict",
                newName: "MainStdDomainDict");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainStdDomainDict",
                table: "MainStdDomainDict",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "MainLowCodeProjectSchema",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Schema = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainLowCodeProjectSchema", x => x.Id);
                });
        }
    }
}
